import Page
from Page import SmartHome
from Base.Base import Base
from selenium.webdriver.common.by import By


class SmartHomeXiaobaiLoginPage(Base):
    """
    智能家居首页

    因其页面命名比较特殊, 故直接采用拼音命名
    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.smarthome_home_btn = (By.XPATH, SmartHome.RESOURCE_ID.format("ivHome"))

        # 左侧的返回键
        self.smarthome_back_btn = (By.XPATH, SmartHome.RESOURCE_ID.format('ivBack'))

        # 小白页面标题
        self.smarthome_xiaobai_title_text = (By.XPATH, Page.TEXT.format("公子小白账号登录"))

        # 小白账户头像图标
        self.smarthome_xiaobai_avatar_icon = (By.XPATH, SmartHome.RESOURCE_ID.format("iv_user_in_edit"))

        # 小白账户输入框
        self.smarthome_xiaobai_login_input = (By.XPATH, SmartHome.RESOURCE_ID.format("et_account"))

        # 小白密码图标
        self.smarthome_xiaobai_password_icon = (By.XPATH, SmartHome.RESOURCE_ID.format("iv_password_in_edit"))

        # 小白密码输入框
        self.smarthome_xiaobai_password_input = (By.XPATH, SmartHome.RESOURCE_ID.format("et_password"))

        # 登录按钮
        self.smarthome_xiaobai_login_btn = (By.XPATH, SmartHome.RESOURCE_ID.format("btn_login"))

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.smarthome_home_btn)

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.smarthome_back_btn)

    def get_xiaoba_title(self):
        """
        获取小白账户标题

        :return:获取元素
        """
        return self.find_element_o(self.smarthome_xiaobai_title_text)

    def get_xiaoba_avatar(self):
        """
        获取小白账户图标

        :return: 获取元素
        """
        return self.find_element_o(self.smarthome_xiaobai_avatar_icon)

    def input_xiaoba_login(self, text):
        """
        小白账户名输入框

        :return:
        """
        self.input_text(self.smarthome_xiaobai_login_input, text)

    def get_xioaba_password(self):
        """
        获取小白密码图标

        :return: 获取元素
        """
        return self.find_element_o(self.smarthome_xiaobai_password_icon)

    def input_xiaoba_password(self, text):
        """
        公子小白账户输入框

        :param text:
        :return:
        """
        self.input_text(self.smarthome_xiaobai_password_input, text)

    def click_xiaoba_login(self):
        """
        点击小白登录按钮

        :return: None
        """
        self.click_element(self.smarthome_xiaobai_login_btn)

    def is_display_smart_home_xiaobai(self):
        """
        是否进入智能家居首页界面

        :return: bool
        """
        return self.is_display(self.smarthome_xiaobai_title_text)
